package org.KeyCrafter.server;

import org.KeyCrafter.cmd.Command;
import org.KeyCrafter.server.aof.AofAttribute;
import org.KeyCrafter.server.aof.LoadingInfo;
import org.KeyCrafter.server.session.ClientSession;

public class DefaultServerContext implements ServerContext {
    KeyCrafterServer server;

    @Override
    public int LRU_CLOCK() {
        return server.LRU_CLOCK();
    }


    @Override
    public KVDB db(int i) {
        return server.db[i];
    }

    @Override
    public int dbNum() {
        return server.dbNum;
    }

    /*
     * 根据给定命令名字，查找命令
     */
    public Command lookupCommand(String name) {
        return server.commands.get(name.toLowerCase());
    }

    @Override
    public void setCurrentClient(ClientSession c) {
        server.currentClient = c;
    }

    @Override
    public void addClient(ClientSession c) {
        server.clients.add(c);
    }

    @Override
    public ServerStatistics getStatistics() {
        return server.statistics;
    }

    @Override
    public AofAttribute getAOFAttribute() {
        return server.aofAttribute;
    }

    @Override
    public BackgroundServer getBackgroundServer() {
        return server.backgroundServe;
    }

    @Override
    public long mstime() {
        return server.mstime;
    }

    @Override
    public LoadingInfo getLoadingInfo() {
        return server.loadingInfo;
    }

    @Override
    public long getDirty() {
        return server.dirty;
    }

    @Override
    public void incrDirty() {
        server.dirty++;
    }

    @Override
    public void addDirty(int delta) {
        server.dirty += delta;
    }

    @Override
    public String getWorkDir() {
        return server.workDir;
    }

}
